package javawdw.security.dao.impl;

import java.util.List;

import javawdw.security.dao.RoleDao;
import javawdw.security.entity.Role;

@SuppressWarnings("unchecked")
public class RoleDaoImpl extends AbstractDaoImpl<Role> implements RoleDao {
	private static final String FIND_BY_USERID = "SELECT ro FROM Role ro, UserRole ur WHERE ur.role.id=ro.id AND ur.user.id=?";
	private static final String FIND_BY_RESOURCEURL = "SELECT ro FROM Role ro, RoleResource rr, Resource re WHERE rr.role.id=ro.id AND rr.resource.id=re.id AND re.url=?";

	public List<Role> findByResourceUrl(String resourceUrl) {
		return getHibernateTemplate().find(FIND_BY_RESOURCEURL, resourceUrl);
	}
	
	public List<Role> findByUserId(String userId) {
		return getHibernateTemplate().find(FIND_BY_USERID, userId);
	}
}